// map.js

Page({
  data: {
    centerX: 10.1,
    centerY: 23.1,
    markers: [],
    polyline: [{
      points: [{
        longitude: 113.1,
        latitude: 23.101229
      }, {
        longitude: 113.1,
        latitude: 23.1
      }],
      color:"#FF0000DD",
      width: 2,
      dottedLine: true
    }],
    controls: [{
      id: 1,
      iconPath: '../../images/icon-address.png',
      position: {
        left: 10,
        top: 10,
        width: 30,
        height: 30
      },
      clickable: true
    }, {
        id: 2,
        iconPath: '../../images/nav-left.png',
        position: {
          left: 250,
          top: 100,
          width: 60,
          height:60
        },
        clickable: true
      }, {
        id: 3,
        iconPath: '../../images/nav-right.png',
        position: {
          left: 250,
          top: 160,
          width: 60,
          height: 60
        },
        clickable: true
      }]
  },
  onReady: function (e) {
    // 使用 wx.createMapContext 获取 map 上下文 
    this.mapCtx = wx.createMapContext('myMap')
  },
  onLoad: function () {
    console.log('地图定位！')
    let that = this
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success: (res) => {
        console.log(res)
        let latitude = 113.1;
        let longitude = 23.101229;
        let marker = this.createMarker(res);
        this.setData({
          centerX: longitude,
          centerY: latitude,
          markers: this.getSchoolMarkers()
        })
      }
    });
  },
  regionchange(e) {
    console.log(e.type)
  },
  markertap(e) {
    console.log(e)
  },
  controltap(e) {
    console.log(e.controlId)
    this.moveToLocation()
  },
  getSchoolMarkers() {
    let markers = [];
    
    return markers;
  },
  moveToLocation: function () {
    this.mapCtx.moveToLocation()
  },
  createMarker(point) {
    let latitude = 113.1;
    let longitude = 23.101229;
    // let latitude = point.latitude;
    // let longitude = point.longitude;
    let marker = {
      iconPath: "/image/location.png",
      id: point.id || 0,
      name: point.name || '',
      latitude: latitude,
      longitude: longitude,
      width: 25,
      height: 48
    };
    return marker;
  },
   controltap(e) {
    var that = this;
    console.log("scale===" + this.data.scale)
    if (e.controlId === 1) {
      that.setData({
        scale: --this.data.scale
      })
    } else {
      that.setData({
        scale: ++this.data.scale
      })
    }
  },

})